package com.example.sourcecodelearning.config;

import com.manticoresearch.client.ApiClient;
import com.manticoresearch.client.api.IndexApi;
import com.manticoresearch.client.api.SearchApi;
import com.manticoresearch.client.api.UtilsApi;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class ManticoreSearchBeanConfiguration {

    @Value("${manticoresearch.url}")
    private String manticoresearchUrl;

    private ApiClient getApiClient() {
        ApiClient client = com.manticoresearch.client.Configuration.getDefaultApiClient();
        client.setBasePath(manticoresearchUrl);
        return client;
    }

    @Bean
    public IndexApi indexApi() {
        ApiClient client = getApiClient();
        return new IndexApi(client);
    }

    @Bean
    public SearchApi searchApi() {
        ApiClient client = getApiClient();
        return new SearchApi(client);
    }

    @Bean
    public UtilsApi utilsApi() {
        ApiClient client = getApiClient();
        return new UtilsApi(client);
    }
}
